<?php
include 'DBconn.php';
class CustomerMaster
{
    public function getAllClients()
    {
        $result=mysql_query("select * from client_header where activestatus=1") or die(mysql_error());
       $ret=array();
        while($row=mysql_fetch_object($result))
        {
            $tmp=new VoClientMaster();
            $tmp->serialnumber=(int)$row->serialnumber;
            $tmp->client_id=$row->client_id;
            $tmp->client_name=$row->client_name;
            $tmp->cust_type=$row->cust_type;
            $tmp->client_country=$row->client_country;
            $tmp->client_off_addr=$row->client_off_addr;
            $tmp->off_phone=$row->off_phone;
            $tmp->client_del_addr=$row->client_del_addr;
            $tmp->del_phone=$row->del_phone;
            $tmp->client_fax=$row->client_fax;
            $tmp->client_email=$row->client_email;
            $tmp->client_url=$row->client_url;
            $tmp->client_contact_person=$row->client_contact_person;
            $tmp->client_contact_phone=$row->client_contact_phone;
            $tmp->client_contact_email=$row->client_contact_email;
            $tmp->client_remarks=$row->client_remarks;
            $tmp->client_regno1=$row->client_regno1;
            $tmp->client_regno2=$row->client_regno2;
            $tmp->client_pricecategory=$row->client_pricecategory;
            $tmp->cre_userid=(int)$row->cre_userid;
            $tmp->cre_datetime=$row->cre_datetime;
            $tmp->activestatus=(boolean)$row->activestatus;
            $ret[]=$tmp;
            }
    mysql_free_result($result);
    return $ret;
    }
    public function addNewClient($VObject)
    {
        $query="insert into client_header(client_id,client_name,cust_type,client_country,client_off_addr,off_phone,client_del_addr,del_phone,client_fax,client_email,client_url,client_contact_person,client_contact_phone,client_contact_email,client_remarks,client_regno1,client_regno2,client_pricecategory,cre_userid,cre_datetime,activestatus) values('$VObject->client_id','$VObject->client_name','$VObject->cust_type','$VObject->client_country','$VObject->client_off_addr','$VObject->off_phone','$VObject->client_del_addr','$VObject->del_phone','$VObject->client_fax','$VObject->client_email','$VObject->client_url','$VObject->client_contact_person','$VObject->client_contact_phone','$VObject->client_contact_email','$VObject->client_remarks','$VObject->client_regno1','$VObject->client_regno2','$VObject->client_pricecategory','$VObject->cre_userid','$VObject->cre_datetime',1)";
        $s=mysql_query($query) or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllClients();
    }
    public function editClient($VObject)
    {
         $query="update client_header set client_id='$VObject->client_id',client_name='$VObject->client_name',cust_type='$VObject->cust_type',client_country='$VObject->client_country',client_off_addr='$VObject->client_off_addr',off_phone='$VObject->off_phone',client_del_addr='$VObject->client_del_addr',del_phone='$VObject->del_phone',client_fax='$VObject->client_fax',client_email='$VObject->client_email',client_url='$VObject->client_url',client_contact_person='$VObject->client_contact_person',client_contact_phone='$VObject->client_contact_phone',client_contact_email='$VObject->client_contact_email',client_remarks='$VObject->client_remarks',client_regno1='$VObject->client_regno1',client_regno2='$VObject->client_regno2',client_pricecategory='$VObject->client_pricecategory',cre_userid='$VObject->cre_userid',cre_datetime='$VObject->cre_datetime' where serialnumber=".$VObject->serialnumber;
        $s=mysql_query($query) or die(mysql_error());
        if ($s=1) 
      {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllClients();
    }
    public function deleteClient($VObject)
    {
         $query="update client_header set activestatus=0 where serialnumber=".$VObject->serialnumber;
        $s=mysql_query($query) or die(mysql_error());
    if ($s=1) 
     {
        mysql_query("COMMIT");
      }
      else
      {
        mysql_query("ROLLBACK");
      }
      return $this->getAllClients();
    }
}

class VoClientMaster
{
    var $serialnumber;
    var $client_id;
    var $client_name;
    var $cust_type;
    var $client_country;
    var $client_off_addr;
    var $off_phone;
    var $client_del_addr;
    var $del_phone;
    var $client_fax;
    var $client_email;
    var $client_url;
    var $client_contact_person;
    var $client_contact_phone;
    var $client_contact_email;
    var $client_remarks;
    var $client_regno1;
    var $client_regno2;
    var $client_pricecategory;
    var $cre_userid;
    var $cre_datetime;
    var $activestatus;
}


?>